<?php
require_once __DIR__.DIRECTORY_SEPARATOR.'extend'.DIRECTORY_SEPARATOR.'workerman' . DIRECTORY_SEPARATOR . 'Autoloader.php';

$listen = 'http://0.0.0.0:2759'; // 定义监听地址

//define('EXTEND_PATH',__DIR__.DIRECTORY_SEPARATOR.'extend'.DIRECTORY_SEPARATOR);

// 创建worker对象
$worker = new \Workerman\Worker($listen);
$worker->count = 4; // 设置进程数
$worker->name = 'mfw_comment'; // 定义worker名称

$logPath = __DIR__.DIRECTORY_SEPARATOR.'log';
if (!file_exists($logPath)){
    mkdir($logPath,0777,true);
}
// 创建文件
$file = fopen($logPath.DIRECTORY_SEPARATOR.'mfw_comment.text','w');
if(!file_exists($logPath.DIRECTORY_SEPARATOR.'mfw_comment.text')){
    return false;
}

\workerman\Worker::$stdoutFile = $logPath.DIRECTORY_SEPARATOR.'mfw_comment.text'; // 以守护进程模式运行，设置输出文件



require_once __DIR__.DIRECTORY_SEPARATOR.'application'.DIRECTORY_SEPARATOR.'mfw_comment'.DIRECTORY_SEPARATOR.'controller'.DIRECTORY_SEPARATOR.'MfwComment.php';
// 引入马蜂窝点评类
$mfwCommentObj = new \app\mfw_comment\controller\MfwComment();

// 调用类的方法
$worker->onWorkerStart = array($mfwCommentObj, 'onWorkerStart');
$worker->onConnect     = array($mfwCommentObj, 'onConnect');
$worker->onMessage     = array($mfwCommentObj, 'onMessage');
$worker->onClose       = array($mfwCommentObj, 'onClose');
$worker->onWorkerStop  = array($mfwCommentObj, 'onWorkerStop');

// 运行worker
\Workerman\Worker::runAll();
